<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class MessageController extends BaseController
{
    public $validate = [
        "announce" => ["rules" => []],
        "clean" => ["rules" => [
        ]],
        "commentReceive" => ["rules" => [
            'receive_id' => 'max:24',
        ]],
        "commentSend" => ["rules" => [
            'sender_id' => 'max:24',
        ]],
        "like" => ["rules" => [
            'receive_id' => 'max:24',
        ]],
        "unread" => ["rules" => [
        ]],
    ];

    /**
     * @path /message/announce
     * @category 消息
     * @title 官方账户消息
     * @method POST
     * @params [{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"消息ID","title":"消息标题","content":{"html":"消息内容","operating":""},"created_at":"创建时间戳"}]}}
     */
    public function announce(Request $request)
    {
        $params = $request->all();

        $data = service()->MessageService->getUserAnnounce($this->getBaseInfo($params));

        return $this->apiReturn($data);
    }

    /**
     * @path /message/clean
     * @category 消息
     * @title 一键清零
     * @method POST
     * @resBody {"success":true,"statusCode":200,"result":true,"message":"OK"}
     */
    public function clean(Request $request)
    {
        $data = service()->MessageService->clearUnread($this->getCurrentUserId());

        return $this->apiReturn($data);
    }

    /**
     * @path /message/comment-receive
     * @category 消息
     * @title 【有备注】我收到的评论
     * @method POST
     * @params [{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}},{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"笔记ID","target_type":"2笔记","type":"1文章笔记，2随手记","is_deleted":0,"content":"笔记内容","article":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}}},{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"笔记ID","target_type":"2笔记","type":"3随手记","is_deleted":0,"content":"笔记内容","image":["1.jpg"]}}]}}
     * @description 1.【前端】示例返回中包含【文章】【全文笔记、随手记】【笔记】三种节点
     */
    public function commentReceive(Request $request)
    {
        $params = $request->all();

        $params['receive_id'] = $this->getCurrentUserId();
        $data = service()->MessageService->getUserReceiveCommentList($params, $this->getCurrentUserId());

        return $this->apiReturn($data);
    }

    /**
     * @path /message/comment-send
     * @category 消息
     * @title 【有备注】我发出的评论
     * @method POST
     * @params [{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}},{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"笔记ID","target_type":"2笔记","type":"1文章笔记，2随手记","is_deleted":0,"content":"笔记内容","article":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}}},{"id":"消息ID","created_at":"创建时间戳","main":{"id":"回复ID","content":"回复内容","target_type":4,"user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"评论/回复ID","content":"评论/回复内容","target_type":"3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"target":{"id":"笔记ID","target_type":"2笔记","type":"3随手记","is_deleted":0,"content":"笔记内容","image":["1.jpg"]}}]}}
     * @description 1.【前端】示例返回中包含【文章】【全文笔记、随手记】【笔记】三种节点
     */
    public function commentSend(Request $request)
    {
        $params = $request->all();

        $params['sender_id'] = $this->getCurrentUserId();
        $data = service()->MessageService->getUserSendCommentList($params, $this->getCurrentUserId());

        return $this->apiReturn($data);
    }

    /**
     * @path /message/like
     * @category 消息
     * @title 【有备注】我收到的赞
     * @method POST
     * @params [{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"消息ID","created_at":"创建时间戳","main":{"target_type":"被赞的主体类型，1文章，2笔记，3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}},{"id":"消息ID","created_at":"创建时间戳","main":{"target_type":"被赞的主体类型，1文章，2笔记，3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"笔记ID","target_type":"2笔记","type":"1文章笔记，2随手记","is_deleted":0,"content":"笔记内容","article":{"id":"文章ID","cover_url":"文章封面图，如1.jpg","description":"文章描述","is_deleted":0,"target_type":1,"title":"文章标题"}}},{"id":"消息ID","created_at":"创建时间戳","main":{"target_type":"被赞的主体类型，1文章，2笔记，3评论，4回复","user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"},"to_user":{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg"}},"child":{"id":"笔记ID","target_type":"2笔记","type":"3随手记","is_deleted":0,"content":"笔记内容","image":["1.jpg"]}}]}}
     * @description 1.【前端】示例返回中包含【文章】【全文笔记、随手记】【笔记】三种节点
     */
    public function like(Request $request)
    {
        $params = $request->all();

        $params['receive_id'] = $this->getCurrentUserId();
        $data = service()->MessageService->getUserReceiveLikeList($params, $this->getCurrentUserId());

        return $this->apiReturn($data);
    }

    /**
     * @path /message/unread
     * @category 消息
     * @title 获取消息数
     * @method POST
     * @resBody {"success":true,"statusCode":200,"result":{"comment":8,"like":99,"announce":109},"message":"OK"}
     */
    public function unread(Request $request)
    {
        $data = service()->MessageService->getUserUnread($this->getCurrentUserId());

        return $this->apiReturn($data);
    }
}
